<?php
include('include/config.inc.php');
if(!isset($_SESSION['s_activId'.$cfgPack])
  || (isset($_SESSION['s_userType'.$cfgPack]) && isset($cfgFileNames['technician'][$_SESSION['s_userType'.$cfgPack]]) 
      && $cfgFileNames['technician'][$_SESSION['s_userType'.$cfgPack]] == 0))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
  $k=0;
	$activeId = ($_SESSION['s_activId'.$cfgPack]);
  $selectuserType = "SELECT userName,userType
                            FROM user
                           WHERE userName = '".$activeId."'";
  $selectuserTypeRes = mysql_query($selectuserType);
  while($userRow = mysql_fetch_array($selectuserTypeRes))
  {
    $userType = $userRow['userType'];
  	$k++;
  }
	$itemDetailArray     = array();
  $selectItem = "SELECT item.itemId,item.categoryId,item.subCategoryId,item.itemName,item.itemMake,item.modelNo,item.currentStock,item.maxLevel,item.minLevel,
                        category.categoryId,category.categoryName,subcategory.subCategoryId,subcategory.subCategoryName
                   FROM item
                   JOIN category
                   JOIN subcategory
                  WHERE item.categoryId = category.categoryId
                    AND item.subCategoryId = subcategory.subCategoryId";
  if(isset($_GET['categoryId'] ) && $_GET['categoryId'] > 0 )
  {
    $selectItem .= " AND item.categoryId = ".$_GET['categoryId'];               
  }
  if(isset($_GET['subCategoryId'] ) && $_GET['subCategoryId'] > 0 )
  {
    $selectItem .= " AND item.subCategoryId = ".$_GET['subCategoryId'];               
  }  
  if(isset($_GET['itemId'] ) && $_GET['itemId'] > 0 )
  {
    $selectItem .= " AND item.itemId = ".$_GET['itemId'];               
  }  
  if(isset($_GET['txtSearch']) && $_GET['txtSearch'] != "")
  {
    $selectItem .= " AND item.itemName = ".$_GET['txtSearch']." ";
  } 
  $selectItem .= " ORDER BY itemName";
               
  $selectItemResult = mysql_query($selectItem);
  $itemRow = mysql_num_rows($selectItemResult);
  $i = 0;
  while($itemRow = mysql_fetch_array($selectItemResult))
  {
    $itemDetailArray[$i]['itemId']          = $itemRow['itemId'];
    $itemDetailArray[$i]['categoryName']    = $itemRow['categoryName'];
    $itemDetailArray[$i]['subCategoryName'] = $itemRow['subCategoryName'];
    $itemDetailArray[$i]['itemName']        = $itemRow['itemName'];
    $itemDetailArray[$i]['itemMake']        = $itemRow['itemMake'];
    $itemDetailArray[$i]['modelNo']         = $itemRow['modelNo'];
    $itemDetailArray[$i]['currentStock']    = $itemRow['currentStock'];
    $itemDetailArray[$i]['maxLevel']        = $itemRow['maxLevel'];
    $itemDetailArray[$i]['minLevel']        = $itemRow['minLevel'];
    $i++;     
  }
  include("./bottom.php");
  $smarty->assign("itemDetailArray",$itemDetailArray);
  $smarty->assign("i",$i);
  $smarty->assign("userType",$userType);
  $smarty->display("productAj.tpl");
}
?>